package com.yefu.yygh.common.utils;

import com.yefu.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

//获取当前用户信息的工具类
public class AuthContextHolder {

    //获取当前用户id
    public static Long getUserId(HttpServletRequest request){
        //从header里面获取到token
        String token = request.getHeader("token");
        //通过jwt从token里面获取userid
        Long userId = JwtHelper.getUserId(token);

        return userId;
    }
    //获取当前用户的名称
    public static String getUserName(HttpServletRequest request){
        //从header里面获取到token
        String token = request.getHeader("token");
        //通过jwt从token里面获取userid
        String userName = JwtHelper.getUserName(token);

        return userName;
    }

}
